package com.csweimei.rentmanagementtreasure.tenant.ui.act;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;

import com.chad.library.BR;
import com.csweimei.rentmanagementtreasure.R;
import com.csweimei.rentmanagementtreasure.base.AppConfig;
import com.csweimei.rentmanagementtreasure.base.AppViewModelFactory;
import com.csweimei.rentmanagementtreasure.databinding.ActivityFollowRecordBinding;
import com.csweimei.rentmanagementtreasure.tenant.viewModel.FollowRecordVM;
import com.google.android.material.tabs.TabLayout;

import me.goldze.mvvmhabit.base.BaseActivity;

public class FollowRecordActivity extends BaseActivity<ActivityFollowRecordBinding, FollowRecordVM> {


    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_follow_record;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    int type = 0;
    @Override
    public void initParam() {
        super.initParam();
        type = getIntent().getIntExtra(AppConfig.BUNDLE_KEY,0);
    }

    @Override
    public void initData() {
        super.initData();
        viewModel.setActivity(this);

        binding.tab.addTab(binding.tab.newTab().setText("待跟进"));
        binding.tab.addTab(binding.tab.newTab().setText("跟进中"));
        binding.tab.getTabAt(type).select();
        viewModel.state.set(type+"");

        binding.tab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewModel.state.set(""+tab.getPosition());
                viewModel.onResume();
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

    }

    @Override
    public FollowRecordVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this,factory).get(FollowRecordVM.class);
    }
}